package leetcode.code0747;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {
	public int dominantIndex(int[] nums) {
		if (nums.length == 1)
			return 0;
		int max1 = -1;
		int max2 = -1;
		int ans = 0;
		for (int i = 0; i < nums.length; i++) {
			int num = nums[i];
			if (num > max1) {
				if (max1 > max2) {
					max2 = max1;
				}
				max1 = num;
				ans = i;
			} else if (num > max2) {
				max2 = num;
			}
		}
		return max2 == 0 ? ans : max1 / max2 < 2 ? -1 : ans;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(3, this.dominantIndex(HelpDebug.str2array3("[0,0,0,1]")));
	}

	@Override
	public void debug2() {
		HelpDebug.compare(1, this.dominantIndex(HelpDebug.str2array3("[3,6,1,0]")));
	}

	@Override
	public void debug3() {
		HelpDebug.compare(-1, this.dominantIndex(HelpDebug.str2array3("[1,2,3,4]")));

	}

	@Override
	public void debug4() {
		HelpDebug.compare(0, this.dominantIndex(HelpDebug.str2array3("[1]")));
	}

	public void debug5() {
		HelpDebug.compare(1, this.dominantIndex(HelpDebug.str2array3("[0,1]")));
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug3();
		so.debug1();
		so.debug2();
		so.debug4();
		so.debug5();

	}

}
